package user;

import book.BookList;
import exception.BorrowException;
import exception.ReturnException;
import ioperation.*;

import java.util.Scanner;

public class NormalUser extends User{

private IOperation[] ioPerations = new IOperation[4];

    public NormalUser(String name,String passWord) {
        super(name,passWord);
        this.ioPerations[0] = new ExitOperation();
        this.ioPerations[1] = new FindOperation();
        this.ioPerations[2] = new BorrowOperation();
        this.ioPerations[3] = new ReturnOperation();
    }

    @Override
    public int menu() {
        System.out.println("欢迎"+this.name+"来到图书管理系统");
        System.out.println("******普通用户界面*****");
        System.out.println("1.查找图书");
        System.out.println("2.借阅图书");
        System.out.println("3.归还图书");
        System.out.println("0.退出系统");
        System.out.println("*********************");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的操作：");
        int choice = scanner.nextInt();
        return choice;
    }

    @Override
    public void doIoperation(int choice, BookList bookList) {
        try{
            ioPerations[choice].work(bookList);
        }catch (BorrowException e){
            e.printStackTrace();
        }catch (ReturnException e){
            e.printStackTrace();
        }
    }
}
